package com.yzr.common.thread.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class CallableTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> integerFutureTask = new FutureTask<>(new MyThread());
        new Thread(integerFutureTask, "mythread").start();
        System.out.println(111);

        Integer integer = integerFutureTask.get();
        System.out.println(integer);
    }

}

class MyThread implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        TimeUnit.SECONDS.sleep(3);
        System.out.println("call()...");
        return 1024;
    }
}
